package 设计模式.观察者模式;

import java.util.ArrayList;
import java.util.List;

public class WatchedImpl implements IWatched {
	// 存放观察者
	private List<IWatcher> list = new ArrayList<IWatcher>();

	@Override
	public void addWatcher(IWatcher watcher) {
		list.add(watcher);
	}

	@Override
	public void removeWatcher(IWatcher watcher) {
		list.remove(watcher);
	}

	@Override
	public void notifyWatchers(String str) {
		// 自动调用实际上是主题进行调用的
		for (IWatcher watcher : list) {
			watcher.update(str);
		}
	}

}